package com.learn.jms.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;

import javax.jms.Destination;
import javax.jms.TextMessage;


/**
 * 《Spring源码深度解析》第13章 Spring消息
 * 接收端实现
 * ActiveMQ下载：http://activemq.apache.org/activemq-5015009-release
 * Windows系统下双击 /bin/win64/activemq.bat 启动消息服务器
 */
public class HelloWorldReciver {
    public static void main(String[] args) throws Exception {
		// 先运行 HelloWorldSender 发送消息，再运行 HelloWorldReciver 接收消息
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext1.xml");
        JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate");
        Destination destination =  (Destination) context.getBean("destination");

        TextMessage msg = (TextMessage) jmsTemplate.receive(destination);
        System.out.println("reviced msg is:" + msg.getText());
    }
    /* Output:
     reviced msg is:大家好这个是测试！
     *///
}
